import lib.problem as problem
import unittest
import lib.arithmetics as arithmetics

class Problem023(problem.Problem):
	def __init__(self):
		problem.Problem.__init__(self, 23)
		
	def listAbundantsUntil(self, n):
		abundants = []
		for i in range(1, n + 1):
			if arithmetics.isAbundant(i):
				abundants.append(i)
				
		return abundants
		
	
	def sumOfResults(self, n):
		allNumbers = list(range(n + 1))
		abundants = self.listAbundantsUntil(n)
		
		for i in abundants:
			for j in abundants:
				pos = i + j
				if pos <= n:
					allNumbers[pos] = 0
		
				
		return arithmetics.sum(allNumbers)
		
	def solve(self):
		return self.sumOfResults(28123)

	
class Problem023Tester(unittest.TestCase):
	
	def setUp(self):
		self.p023 = Problem023()
	
	def testSumOfResults100(self):
		self.assertEquals(2766, self.p023.sumOfResults(100))
	
		
	def testSumOfResults28123(self):
		self.assertEquals(4179871, self.p023.sumOfResults(28123))
	
	def testSolve(self):
		self.assertEquals(4179871, self.p023.solve())
